<?php
namespace Modules\Taxonomy\Entity;

use Core\Mvc\Entity\Entity as BaseEntity;

class Term extends BaseEntity
{
    protected $_entity = 'term';
    protected $_module = 'taxonomy';
    public $keywords = '';
    public $description = '';
    public $name;
    public $hot = 0;
    public $weight = 10;

    public function getLinks()
    {
        if (!$this->_links) {
            $this->_links = [
                'edit' => [
                    'href' => [
                        'for' => 'adminTermEdit',
                        'id' => $this->getId(),
                    ],
                    'data-target' => 'right_handle',
                    'icon' => 'info',
                    'name' => '编辑',
                ],
                'delete' => [
                    'href' => [
                        'for' => 'adminTermDelete',
                        'id' => $this->getId(),
                    ],
                    'data-target' => 'main',
                    'icon' => 'danger',
                    'name' => '删除',
                ],
            ];
        }
        return $this->_links;
    }

    public function getChildren()
    {
        $query = array(
            'conditions' => [
                'parent' => $this->getId(),
            ],
            'order' => 'weight',
        );
        $output = self::find($query);
        return $output;
    }
}
